package com.example.Arithmetic.Lettcode;

import java.util.ArrayList;
import java.util.List;

/**
 * 日期：2024/1/2
 * 时间：9:26
 * 描述：力扣22题，括号生成
 */
public class E01Lettcode22 {
    public List<String> generateParenthesis(int n) {
        ArrayList<String>[] arrayLists = new ArrayList[n + 1];
        arrayLists[0] = new ArrayList(List.of(""));
        arrayLists[1] = new ArrayList(List.of("()"));
        for (int i = 2; i < n + 1; i++) {
            arrayLists[i] = new ArrayList();
            for (int j = 0; j < i; j++) {
                for (String s:arrayLists[j]){
                    for (String ss:arrayLists[i-1-j]){
                        arrayLists[i].add("("+s+")"+ss);
                    }
                }
            }
        }
        return arrayLists[n];
    }
    public static void main(String[] args) {
        E01Lettcode22 code = new E01Lettcode22();
        System.out.println(code.generateParenthesis(10));
    }
}

